<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2011 Alex Paréj.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE html>
<ui:component xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:p="http://primefaces.org/ui"
              xmlns:md="http://java.sun.com/jsf/composite/md"
              xmlns:fn="http://java.sun.com/jsp/jstl/functions">
    <h:form id="megosztasokForm">
        <p:dataTable id="megosztasokTabla"
                     value="#{controller.dokumentumok}"
                     var="dok"
                     selectionMode="multiple"
                     selection="#{controller.valasztottDokumentumok}"
                     sortBy="#{controller.getSorrendKedvencek(dok)}"
                     rowKey="#{dok.id}"
                     emptyMessage="#{msg.nincsAdat}"
                     rows="#{msg.datatableRows}" 
                     paginator="true"
                     paginatorPosition="bottom"
                     paginatorTemplate="#{msg.datatablePaginatorTemplate}"  
                     rowsPerPageTemplate="#{msg.datatableRowsPerPageTemplate}"
                     filteredValue="#{controller.filteredDokumentumok}">
            <p:ajax event="rowSelect" update="funkcioGombok"/>
            <p:ajax event="rowUnselect" update="funkcioGombok"/>
            <f:facet name="header">
                #{dataTableFejlec}
            </f:facet>
            <p:column style="width: 20px">
                <p:rowToggler rendered="#{!empty dok.megjegyzes}"/>
            </p:column>
            <p:column sortBy="#{controller.getSorrendKedvencek(dok)}" 
                      rendered="#{kedvenc ? false : true}"
                      style="width: 20px">
                <f:facet name="header">
                    <span class="ui-icon ui-icon-star" title="#{msg.kedvencek}"/>
                </f:facet>
                <span class="#{controller.isKedvenc(dok) ? 'ui-icon ui-icon-star' : ''}"/>
            </p:column>
            <p:column headerText="#{msg.nev}" sortBy="#{dok.nev}"
                      filterBy="#{dok.nev}">
                #{dok.nev}
            </p:column>
            <p:column headerText="#{msg.tipus}" sortBy="#{dok.kiterjesztes}"
                      filterBy="#{dok.kiterjesztes}">
                #{dok.kiterjesztes}
            </p:column>
            <p:column headerText="#{msg.meret}" sortBy="#{dok.meret}">
                #{utilController.getMeret(dok)}
            </p:column>
            <p:column headerText="#{msg.tulajdonos}" sortBy="#{dok.letrehozo.email}">
                <md:outputDate value="#{dok.letrehozo.email}"/>
            </p:column>
            <p:rowExpansion>
                <div class="adatMezok">
                    <ul>
                        <li>
                            <p><h:outputText value="#{msg.leiras}"/></p>
                        <h:outputText value="#{dok.megjegyzes}"/>
                        </li>
                    </ul>
                </div>
            </p:rowExpansion>
            <f:facet name="footer">
                <div style="float:left;padding: 0.4em">
                    #{fn:length(controller.dokumentumok)} #{msg.db}
                </div>
                <div style="text-align: right">
                    <p:outputPanel id="funkcioGombok">
                        <p:commandButton icon="#{kedvenc ? 'ui-icon-cancel' : 'ui-icon-star'}" update="@form"
                                         actionListener="#{controller.kapcsolKedvencListener()}"
                                         disabled="#{controller.nincsDokumentumValasztva}"/>
                        <p:commandButton icon="ui-icon-circle-arrow-s" title="#{msg.letolt}"
                                         disabled="#{controller.nincsDokumentumValasztva}"
                                         ajax="false">
                            <p:fileDownload value="#{controller.letoltendoDokumentumok}" />  
                        </p:commandButton>
                    </p:outputPanel>
                </div>
            </f:facet>
        </p:dataTable>
    </h:form>
</ui:component>